package com.shuzijun.leetcode.editor.cn;

import java.util.HashSet;

public class ZuiChangBuHanZhongFuZiFuDeZiZiFuChuanLcof{
    public static void main(String[] args) {
         Solution solution = new ZuiChangBuHanZhongFuZiFuDeZiZiFuChuanLcof().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int lengthOfLongestSubstring(String s) {
        int n = s.length();
        if (n == 0) return 0;
        int p = 0;
        int q = 0;
        HashSet<Character> set = new HashSet<>();
        int maxLen = 0;
        while (q < n){
            char c = s.charAt(q);
            if (!set.contains(c)){
                set.add(c);
                q++;
                if (q-p > maxLen) maxLen = q-p;
                continue;
            }

            while (set.contains(c)){
                set.remove(s.charAt(p));
                p++;
            }
        }
        return maxLen;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}